package cz.muni.fi.pa165.sportclubmanager.dto;

import cz.muni.fi.pa165.sportclubmanager.entity.PlayerOnRoster;

/**
 *
 * @author Michal Prokeš, 72758
 */
public class RosterDTOMapping {
    /**
     * Map PlayerOnRoster to basic DTO object
     * @param p Player on Roster object
     * @return DTO object with all attributes
     */
     public static RosterDTO toDTO(PlayerOnRoster p) {
        if(p==null) { return null; }
        
        RosterDTO r = new RosterDTO();
        
        r.setId(p.getId());
        r.setTeam(TeamDTOMapping.toDto(p.getTeam()));
        r.setPlayer(PlayerDTOMapping.toDto(p.getPlayer()));
        r.setNumber(p.getNumber());         
        
        return r;
    }
      
    /**
    * Map RosterDTO ro PlayerOnRoster entity
    * @param r RosterDTO object
    * @return PlayerOnRoster entity
    */
    public static PlayerOnRoster toEntity(RosterDTO r) {
        if(r==null) { return null; }
        
        PlayerOnRoster p = new PlayerOnRoster();
        
        p.setId(r.getId());
        p.setTeam(TeamDTOMapping.toEntity(r.getTeam()));
        p.setPlayer(PlayerDTOMapping.toEntity(r.getPlayer()));
        p.setNumber(r.getNumber());         
        
        return p;
   }
    
}
